package Utils;

import GUI.ChatFrame;

import java.util.HashMap;

/**
 * The type Chat manage.
 *
 * @author dzr
 * @version 1.0
 */
public class ChatManage {
    /**
     * The constant chatFrames.
     */
    public static HashMap<Integer, ChatFrame> chatFrames = new HashMap<>();

    /**
     * Add chatFrame.
     *
     * @param f_uid     the friend's uid
     * @param chatFrame the chat frame
     */
    public static void addChat(int f_uid, ChatFrame chatFrame){
        chatFrames.put(f_uid, chatFrame);
    }

    /**
     * Get specific chat frame with specific friend.
     *
     * @param f_uid the friend's uid
     * @return the chat frame
     */
    public static ChatFrame getChat(int f_uid){
        return  chatFrames.get(f_uid);
    }

    /**
     * if chat with specific friend already exists.
     *
     * @param f_uid the friend's uid
     * @return the boolean
     */
    public static boolean hasChat(int f_uid){
        return chatFrames.containsKey(f_uid);
    }

    /**
     * Close chat with specific friend.
     *
     * @param f_uid the friend's uid
     */
    public static void closeChat(int f_uid){
        chatFrames.get(f_uid).close();
    }

    /**
     * Close all chatFrame.
     */
    public static void closeAllChat(){
        for (int key:
             chatFrames.keySet()) {
            closeChat(key);
        }
    }
}
